<?php

require_once 'db.php';

class works extends db {

    public function selectW($page=NULL) {
        $rows=array();
        $this->getConnection();
        $begin=($page-1)*PAGE; 
        $query = 'SELECT * FROM sales LIMIT ' .$begin.",".PAGE;
        $works = $this->query($query);
         foreach ($works as $list_works):
            if(strlen($list_works['name']) > 10){
                $rows[]=$list_works;
            };
        endforeach;
        return $rows;
    }
    public function selectW1($page=NULL) {
        $rows=array();
        $this->getConnection();
        $begin=($page-1)*3; 
        $query = 'SELECT * FROM sales LIMIT ' .$begin.",3";
        $works = $this->query($query);
         foreach ($works as $list_works):
            if(strlen($list_works['name']) > 10){
                $rows[]=$list_works;
            };
        endforeach;
        return $rows;
    }
    public function selectW2($page=NULL) {
        $rows=array();
        $this->getConnection();
        $begin=($page+4)*3; 
        $query = 'SELECT * FROM sales LIMIT ' .$begin.",3";
        $works = $this->query($query);
         foreach ($works as $list_works):
            if(strlen($list_works['name']) > 10){
                $rows[]=$list_works;
            };
        endforeach;
        return $rows;
    }
    public function selectW3($page=NULL) {
        $rows=array();
        $this->getConnection();
        $begin=($page+9)*3; 
        $query = 'SELECT * FROM sales LIMIT ' .$begin.",3";
        $works = $this->query($query);
         foreach ($works as $list_works):
            if(strlen($list_works['name']) > 10){
                $rows[]=$list_works;
            };
        endforeach;
        return $rows;
    }
    public function selectW4($page=NULL) {
        $rows=array();
        $this->getConnection();
        $begin=($page+14)*3; 
        $query = 'SELECT * FROM sales LIMIT ' .$begin.",3";
        $works = $this->query($query);
         foreach ($works as $list_works):
            if(strlen($list_works['name']) > 10){
                $rows[]=$list_works;
            };
        endforeach;
        return $rows;
    }
     public function countW() {
        $this->getConnection();
        $query = 'SELECT * FROM sales';
        $works = $this->query($query);
        return count($works);
    }
    public function selectLenW() {
        $this->getConnection();
        $query = 'SELECT * FROM sales ';
        $works = $this->query($query);
        foreach ($works as $list_works):
           {
                echo $list_works['name'];
                echo $list_works['price'] ;
                echo $list_works['image'] ;
                
            };
        endforeach;
        return $works;
    }
    public function upda_te($param = NULL){
         $this->getConnection();
         $query = "update sales 
                   set image values($param)";
         var_dump($param);
         $result = mysql_query($query);
         var_dump($result) ;
         if($result)
             return "suceerly";
         else{
             return"failed";
         }
    }
    public function select_edit($page = NULL, $id = NULL) {
        $this->getconnection();
        $where = "";
        if (!empty($id))
            $where = "where id=$id";
        $limit = "";
        if (!empty($page))
            $limit = 'limit ' . $begin . ',' . PER_PAGE;
        $begin = ($page - 1) * PER_PAGE;
        $query = "SELECT * FROM sales $where $limit";
        $result = mysql_query($query);
        $result = mysql_fetch_assoc($result);
        return $result;
        
        
    }
    
   public function update($array=null){
        $query = "Update sales set name='".$array['name']."', image='".$array['img']."' where id=".$array['id'];
       echo $query;
        mysql_query($query);
        if( mysql_query($query))
            echo "ok";
        else
            echo "fail";
        
    }
    public function updatend($array=null){
        $query = "Update sales set name='".$array['name']."' where id=".$array['id'];
       echo $query;
        mysql_query($query);
        if( mysql_query($query))
            echo "ok";
        else
            echo "fail";
    }
     public function login($username = NULL,$password = NULL) {
        $this->getConnection();
        $query = "SELECT * FROM user WHERE name='".$username."' && password='".$password."'";
        $user = $this->query($query);
        return $user;
    }
}
?>
